The next topic is the final and last component that filters inbound
requests to a cloud run service. This component is IAM which lets you
filter traffic based on the identity of the center. IAM checks every incoming
request to a Cloud Run service. All requests to a Cloud Run service
passed through and are evaluated by IAM. To control this type of incoming request,
you will need to configure IAM with an IAM policy that
attaches to the Cloud Run service. IAM on Cloud Run enables two use cases. First, it lets you allow access to
specific service accounts only, or second you can allow unauthenticated
access which is basically making your service publicly accessible
without a login being required. IAM protects every Cloud Run service
similar to how it protects every administrative API on google cloud. For every incoming request,
IAM identifies the caller, if there was an authorization
header part of the request, checks whether there is a corresponding
entry in the IAM policy, and accepts or rejects the request based on
the policy attached to that resource. Only authorized requests are forwarded. Let's look closely at the IAM policy,
the one attached to the Cloud Run service. An IAM policy contains
a list of policy bindings. A policy binding binds member
to a role in order to grant it permission on a resource. In this specific case,
the resource is a Cloud Run service and the roll is called Cloud Run Invoker. Let's take a look at the types of
identities that are relevant when assigning the Cloud Run Invoker role. Service account. Everything that needs to
make calls to other APIs and google cloud has an associated
service account or a robot identity. All users. If you bind all users with the role
Cloud Run Invoker, you're essentially disabling cloud IAM and letting all
unauthenticated requests through. Maybe you remember the third identity
type from the module on IAM. You can also grant the human
identity a google account, the Cloud Run Invoker role. However, the human identity is not
common in a policy binding with the Cloud Run Invoker role. IAM is not meant to enable user logins. If you're calling an IAM
protected service as a human, it involves generating an access
token in the terminal. Now, let's take a look at the most
important use case of IAM with Cloud Run services. You use IAM to selectively allow
certain service accounts or google cloud services to
access your Cloud Run service. Here are examples of a few use cases, Pub/
Sub push subscription, Cloud Run service, Workflows workflow, Cloud Run services
through a Cloud Tasks Queue and any other service on google cloud
with a service account identity. Google cloud services like Pub/ Sub and Workflows have built-in support
to call IAM protected services. They'll use their service identity
to authenticate requests but you'll need to configure them to do so. So what does it mean to send
an authenticated request? It means that your request has
a header with an identity token. This token is an Open ID connect,
OIDC token. An OIDC token is a standardized
chase on web token or JWT. If you've worked with JWT tokens in
the past, the OIDC tokens look familiar. The token contains the audience,
destination service URL, an expiration time no longer
than one hour in the future, and the caller identity, a service account ID. A cryptographic signature signed
by google proves that the token has not been tampered with. To provide access,
IAM uses the information in the token. Sending authenticated requests
from your application, you can use one of the client libraries to send
requests with a google signed ID token. If you use the google cloud
services such as Pub/ Sub, OIDC tokens are automatically added. IAM also enables public access
of a Cloud Run service. If you bind the Cloud Run Invoker
with all users and attach the binding to a Cloud Run
service through an I AM policy, you're allowing public or
unauthenticated access to that service. It's worth noting that Cloud Run
manages this transparency for you if you enable allow public invocation
when you deploy your application. We've just discussed the three ways you
can control inbound requests to your serverless applications. Let's summarize the three
topics we've just covered. Google Cloud Armor, you can use Google
Cloud Armor to apply rule-based content filters to traffic from
Cloud Load Balancing. Its main use case is to protect a web
application from attackers using content based rules that inspect
the http request content. Pre configured rules exist to
mitigate the following attacks. Cross site scripting, SQL injection
attacks, local file inclusion attacks, remote file inclusion attacks and
remote code execution attacks. Ingress settings, the main use case for
ingress settings is to allow only request from resources on the VPC and
disable the default URL if you're using the global https load
balancer for inbound requests. And finally IAM, you can use IAM to
restrict access to certain service accounts or
google cloud services such as Pub/ Sub.